home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hobby / ast44src.zip / PLACALC.H < prev    next >
C/C++ Source or Header  |  1995-02-11  |  17KB  |  454 lines

  1. /*
  2. ** Astrolog (Version 4.40) File: placalc.h
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1995 by Walter D. Pullen
  6. ** (astara@u.washington.edu). Permission is granted to freely use and
  7. ** distribute these routines provided one doesn't sell, restrict, or
  8. ** profit from them in any way. Modification is allowed provided these
  9. ** notices remain with any altered or edited versions of the program.
  10. **
  11. ** The main planetary calculation routines used in this program have
  12. ** been Copyrighted and the core of this program is basically a
  13. ** conversion to C of the routines created by James Neely as listed in
  14. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  15. ** available from Matrix Software. The copyright gives us permission to
  16. ** use the routines for personal use but not to sell them or profit from
  17. ** them in any way.
  18. **
  19. ** The PostScript code within the core graphics routines are programmed
  20. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  21. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  22. **
  23. ** The extended accurate ephemeris databases and formulas are from the
  24. ** calculation routines in the program "Placalc" and are programmed and
  25. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  26. ** (alois@azur.ch). The use of that source code is subject to
  27. ** regulations made by Astrodienst Zurich, and the code is not in the
  28. ** public domain. This copyright notice must not be changed or removed
  29. ** by any user of this program.
  30. **
  31. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  32. ** X Window graphics initially programmed 10/23-29/1991.
  33. ** PostScript graphics initially programmed 11/29-30/1992.
  34. ** Last code change made 1/29/1995.
  35. */
  36.  
  37. #include "astrolog.h"
  38.  
  39.  
  40. #define EPHE_PATH EPHE_DIR
  41. #define HUGE8 1.7E+308     /* biggest value for REAL8 */
  42.  
  43. extern int lrz_file_posit();
  44. extern int chi_file_posit();
  45. extern int outer_hel();
  46. extern void longreorder();
  47. extern int inpolq();
  48.  
  49. #ifdef PLACALC
  50. /************************************************************
  51. $Header: placalc.h,v 1.4 93/03/22 10:08:39 alois Exp $
  52. definitions and constants for planetary routines
  53.  
  54. ATTENTION: PLACALC USERS ON MSDOS:
  55. See the note close to the end of this file regarding EPHE_PATH.
  56.  
  57. ---------------------------------------------------------------
  58. | Copyright Astrodienst AG and Alois Treindl, 1991, 1993.     |
  59. | The use of this source code is subject to regulations made  |
  60. | by Astrodienst Zurich. The code is NOT in the public domain.|
  61. |                                                             |
  62. | This copyright notice must not be changed or removed        |
  63. | by any user of this program.                                |
  64. ---------------------------------------------------------------
  65. ************************************************************/
  66.  
  67. /************************************************************
  68. $Header: ourdef.h,v 1.2 91/11/16 16:21:37 alois Exp $
  69. definitions and constants for all Astrodienst C programs
  70. contains only declarations and #defines, no global variables.
  71. auto-dectection of MSDOS (TURBO_C or MS_C) or HPUNIX
  72. ************************************************************/
  73.  
  74. #ifdef MSDOS  /* already defined by some DOS compilers */
  75. #undef MSDOS
  76. #define MSDOS 1
  77. #endif
  78.  
  79. #ifdef __TURBOC__ /* defined by turboc */
  80. #ifndef MSDOS
  81. #define MSDOS 1
  82. #endif
  83. #define TURBO_C
  84. #endif
  85.  
  86. #if MSDOS
  87. #define HPUNIX 0
  88. #ifndef TURBO_C
  89. #define MS_C /* assume Microsoft C compiler */
  90. #endif
  91. #else
  92. #define MSDOS 0
  93. #define HPUNIX 1
  94. #ifndef _HPUX_SOURCE
  95. #define _HPUX_SOURCE
  96. #endif
  97. #endif
  98.  
  99. #include <stdlib.h>
  100. #if HPUNIX
  101. #ifndef MAC
  102. #include <unistd.h>
  103. #endif
  104. #endif
  105.  
  106. #ifndef OK 
  107. #define OK 0
  108. #define ERR (-1)
  109. #endif
  110.  
  111.  
  112. #define UCHP (unsigned char*)  /* used for casting *char  */
  113. #define UCP (unsigned char*)  /* used for casting *char  */
  114. #define SCP (char*)     /* used for casting *unsigned char */
  115. #define UCHAR unsigned char
  116.  
  117. #if HPUNIX
  118. #ifndef MAC
  119. #include <malloc.h>
  120. #endif
  121. typedef double  REAL8;  /* real with at least 64 bit precision */
  122. typedef float   REAL4;  /* real with at least 32 bit precision */
  123. typedef long     INT4;   /* signed integer with at least 32 bit precision */
  124. typedef unsigned long UINT4; 
  125. /* unsigned integer with at least 32 bit precision */
  126. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  127. typedef int     INT1;   /* signed integer with at least 8  bit precision */
  128. #ifndef dbd_VERSION /* db_vista defines boolean in vista.h already */
  129. typedef int     BOOLEAN;
  130. #endif
  131. typedef unsigned short UINT2; /* unsigned 16 bits */
  132. #define ABS4  abs   /* abs function for long */
  133. #endif
  134.  
  135. #if MSDOS 
  136. #ifdef TURBO_C
  137. #include <alloc.h>    /* MSC needs malloc ! */
  138. #else
  139. #include <malloc.h>
  140. #endif
  141. typedef double  REAL8;  /* real with at least 64 bit precision */
  142. typedef float   REAL4;  /* real with at least 32 bit precision */
  143. typedef long    INT4;   /* signed integer with at least 32 bit precision */
  144. typedef unsigned long UINT4;
  145.                         /* unsigned integer with at least 32 bit precision */
  146. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  147. typedef int     INT1; /* signed integer with at least 8  bit precision */
  148. typedef int     BOOLEAN;
  149. typedef unsigned int UINT2; /* unsigned 16 bits */
  150. #define ABS4  labs    /* abs function for long */ 
  151. #endif
  152.  
  153. #define COS8 cos
  154. #define SIN8 sin
  155. #define ASIN8 asin
  156. #define TAN8 tan
  157. #define ATAN8 atan
  158. #define ATAN28 atan2
  159. #define EXP10(x) pow(10.0, (x))
  160. #define ABS8(x) fabs(x)
  161.  
  162. #define TANERRLIMIT 1.0E-10     /* used to check for arguments close to pi */
  163. #define NEAR_ZERO   1.0E-16     /* used to compare for divisors close to 0 */
  164. #define BIGREAL     1.0E+38
  165.  
  166. #define DEGTORAD 0.0174532925199433
  167. #define RADTODEG 57.2957795130823
  168.  
  169. typedef INT4 centisec;   /* centiseconds used for angles and times */
  170. #define CS   (centisec)  /* use for casting */
  171. #define CSEC centisec    /* use for typing */
  172.  
  173. #define DEG     (360000L)   /* degree expressed in centiseconds */
  174. #define DEG7_30 (2700000L)  /* 7.5 degrees */
  175. #define DEG15   (15 * DEG)
  176. #define DEG24   (24 * DEG)
  177. #define DEG30   (30 * DEG)
  178. #define DEG60   (60 * DEG)
  179. #define DEG90   (90 * DEG)
  180. #define DEG120  (120 * DEG)
  181. #define DEG150  (150 * DEG)
  182. #define DEG180  (180 * DEG)
  183. #define DEG270  (270 * DEG)
  184. #define DEG360  (360 * DEG)
  185.  
  186. #define CSTORAD 4.84813681109536E-08 /* centisec to rad: pi / 180 /3600/100 */
  187. #define RADTOCS 2.06264806247096E+07 /* rad to centisec 180*3600*100/pi */
  188.  
  189. #define DEG2MSEC 3600000.0  /* degree to milliseconds */
  190. #define DEG2CSEC 360000.0   /* degree to centiseconds */
  191.  
  192. #define SEC2CSEC 100  /* seconds to centiseconds */
  193.  
  194. #define CS2DEG    (1.0/360000.0)  /* centisec to degree */
  195. #define CS2CIRCLE (CS2DEG/360.0)  /* centisec to circle */
  196. #define AU2INT    1e7             /* factor for long storage of A.U. */
  197.  
  198. #define CSMIN 6000L
  199. #define CSSEC 100L
  200.  
  201. #define SINDEG(x) sin(DEGTORAD * (x))
  202. #define COSDEG(x) cos(DEGTORAD * (x))
  203. #define TANDEG(x) tan(DEGTORAD * (x))
  204. #define SINCS(x)  sin((double)(CSTORAD * (x)))
  205. #define COSCS(x)  cos((double)(CSTORAD * (x)))
  206. #define TANCS(x)  tan((double)(CSTORAD * (x)))
  207.  
  208. /*************************************************************
  209. Exported functions:
  210.  
  211. In all functions the variable jd_ad indicates the use of
  212. Astrodienst relative julian days, and jd the use of absolute
  213. julian days.
  214. *************************************************************/
  215.  
  216. extern int nacalc();
  217. extern int calcserv();
  218. extern void helup();
  219. extern void togeo();
  220. extern int calc();
  221. extern int rel_geo();
  222. extern int hel();
  223. extern int moon();
  224. extern REAL8 sidtime();
  225. extern REAL8 smod8360();
  226. extern REAL8 mod8360();
  227. extern REAL8 diff8360();
  228. extern REAL8 test_near_zero();
  229. extern REAL8 deltat();
  230. extern void to_mean_ekl();
  231. extern int afl2planet();
  232. extern void disturb();
  233. extern REAL8 fnu();
  234.  
  235. /*************************************************************
  236. exported variables
  237. *************************************************************/
  238.  
  239. extern REAL8 meanekl;
  240. extern REAL8 ekl;
  241. extern REAL8 nut;
  242.  
  243. extern struct elements { /* actual elements at time thelup */
  244.   REAL8 tj,     /* centuries from epoch */
  245.   lg,     /* mean longitude in degrees of arc*/
  246.   pe,     /* longitude of the perihelion in degrees of arc*/
  247.   ex,     /* excentricity in degrees of arc*/
  248.   kn,     /* longitude of node in degrees of arc*/
  249.   in,     /* inclination of the orbit in degrees of arc*/
  250.   ma;     /* mean anomaly in degrees of arc*/
  251. } el [];
  252.  
  253. extern char *ephe_path;
  254.  
  255. /*************************************************************
  256. definitions
  257. *************************************************************/
  258.  
  259. /*
  260. * planet index numbers, used to identify a planet in calc() and
  261. * other related functions.
  262. */
  263. #define CALC_ONLY_ECL_NUT -1  /* pseudo planet index for calls to calc */
  264. #define SUN 0   /* used synonymously for earth too */
  265. #define EARTH 0
  266. #define MOON  1
  267. #define MERCURY 2
  268. #define VENUS 3
  269. #define MARS  4
  270. #define JUPITER 5
  271. #define SATURN  6
  272. #define URANUS  7
  273. #define NEPTUNE 8
  274. #define PLUTO 9
  275. #define LASTPLANET PLUTO
  276. #define MEAN_NODE  10
  277. #define TRUE_NODE  11
  278. #define CHIRON     12
  279. #define CALC_N     13 /* number of planets in placalc module */
  280. #define LILITH     13 /* Lilith is separate, not included in standard set
  281.   of placalc planets. This is required because
  282.   otherwise some string server calls would
  283.   suddenly return a higher number of fields. */
  284.  
  285. /*
  286. * in a bitlist flag each planet is represented by a bit;
  287. * all 13 defined planets can be called at once with
  288. * LILITH is not automatically included
  289. */
  290. #define CALC_ALL_PLANET_BITS ((1 << 13) - 1) /* bits 0..12 set */
  291.  
  292. #define J2000 2451545.0 /* Epoch of JPL ephemeris DE200, absolute */
  293. #define J1950  2433282.423  /* Epoch of JPL ephemeris DE102 */
  294. #define JUL_OFFSET 2433282.0  /* offset of Astrodienst relative Julian date */
  295. #define EPOCH1850 -36524.0  /* jupiter,saturn 0 jan 1850, 12:00 */
  296. #define EPOCH1900 -18262.0  /* inner planets  0 jan 1900, 12:00 */
  297. #define EPOCH1950  0.0    /* pluto    0 jan 1950, 12:00 */
  298.                 /* this is the origin of the Astrodienst
  299.                    relative julian calendar system */
  300. #define EPOCH1960 3653.0 /* uranus,neptune 1 jan 1960, 12:00 */
  301.  
  302. #define ENDMARK 99 /* used to mark the end of disturbation terms */
  303.  
  304. #define NODE_INTERVAL 0.005        /* days, = 7m20s */
  305. #define MOON_SPEED_INTERVAL 0.0001 /* 8.64 seconds later */
  306.  
  307. /*
  308. * flag bits used in calc and calcserv
  309. */
  310. #define CALC_BIT_HELIO 1   /* geo/helio */
  311. #define CALC_BIT_NOAPP 2   /* apparent/true positions */
  312. #define CALC_BIT_NONUT 4   /* true eq. of date/ mean equ. of date */
  313. #define CALC_BIT_EPHE  8   /* universal/ephemeris time */
  314. #define CALC_BIT_SPEED 16  /* without/with speed */
  315. #define CALC_BIT_BETA  32  /* without/with latitude */
  316. #define CALC_BIT_RGEO  64  /* without/with relative rgeo */
  317. #define CALC_BIT_RAU   128 /* without/with real radius */
  318. #define CALC_BIT_MUST_USE_EPHE 256 /* epheserv may not use calc */
  319. #define CALC_BIT_MAY_USE_EPHE  512 /* calcserv may use ephread */
  320.  
  321. /* ephemeris file path for MSDOS */
  322.  
  323. /*****************************************************************************
  324. ATTENTION: PLACALC USERS ON MSDOS:
  325.  
  326. EPHE_PATH indicates where the ephemeris files LRZ_nnn and CHI_nnn
  327. are found in you system.
  328. EPHE_PATH is only used once at the beginning of placalc.c to initialize
  329. the global variable ephe_path.
  330.  
  331. If you do not have the ephemeris files in \PAIR\EPHE, you must do one of
  332. two things:
  333. - change the #define statement below to point to your ephemeris directory
  334. - OR change the global char *ephe_path before  you call any placalc
  335. function.
  336. Take care, that ephe_path ends NOT with the directory character ('\' in DOS).
  337. *****************************************************************************/
  338.  
  339. #define EPHE_STEP 80              /* days step in LRZ ephe */
  340. #define EPHE_DAYS_PER_FILE 100000 /* days per ephe file */
  341. #define EPHE_OUTER "LRZ5_"        /* file name prefix */
  342. #define EPHE_OUTER_BSIZE  60      /* blocksize  */
  343. #define EPHE_CHIRON "CHI_"        /* file name prefix */
  344. #define EPHE_CHIRON_BSIZE 12      /* blocksize  */
  345.  
  346. /********************************************
  347. About the format of the ephemeris files
  348. ----------------------------------------
  349. We use currently ephemeris files with steps of 80 days.
  350. There are 1250 "records" in each file, so that one file
  351. spans 100000 days.
  352. We have two types of ephemeris files:
  353. LRZ5_nn   for the outer planets Jupiter ... Pluto
  354. CHI_nn  for Chiron.
  355. nn is an expression derived from the first julian daynumber on the
  356. file. Jd 2100'000 to 2199'920 is on file LRZ5_21 and CHI_21;
  357. for negative Jd we use the filenames LRZ5_Mxx  with M indicating the minus.
  358.  
  359. Given the jd for which you want the ephemeris, it is simple to build
  360. the filename and use fseek() within the file to go where the data is.
  361. This is done by the functions lrz_file_posit() and chi_file_posit().
  362.  
  363. The stored coordinates are for each date and planet:
  364. L = ecliptic longitude relative to mean exquinox of date,
  365. in units of milliseconds of acr (1/3600000 degree) as type long;
  366. R = radius vector, units of 10-7 AU, as type long.
  367. Z = disctance of ecliptic; Z = R * sin(latitude); in units of 10-7 AU,
  368. as type long.
  369. The data is stored in the byte ordering of the Astrodienst HPUX machines,
  370. which is most significant byte first. It is not the same byte ordering
  371. as on Intel processors; the function longreorder() converts between
  372. the disk file format and the internal format of MSDOS machines.
  373.  
  374. For LRZ5- files, we have 60-byte records LRZ(Jupiter),LRZ(Saturn),
  375. LRZ(Uranus), LRZ(Neptune), LRZ(Pluto). 
  376. For CHI-files we have 12-byte records LRZ.
  377.  
  378. ************************************************/
  379.  
  380.  
  381. /*************************************************************
  382. placalc2.c definitions
  383. *************************************************************/
  384.  
  385. #define SDNUM 20
  386. #define NUM_MOON_CORR 93
  387.  
  388. struct eledata {
  389. REAL8 axis,   /* mean distance, in a.u., A(N) in basic */
  390. period,   /* days for one revolution, P(N) in basic */
  391. epoch,    /* relative juldate of epoch, Ep(N) in basic */
  392. /* T = distance to epoch in jul.centuries 36525 day*/
  393. lg0,lg1,lg2,lg3,/* deg(epoch), degree/day, seconds/T^2,seconds/T^3 */
  394. /* Pd(N,0..2) in basic, lg3 was not present */
  395. pe0,pe1,pe2,pe3,/* deg(epoch), seconds/T,  seconds/T^2,seconds/T^3 */
  396. /* Pd(N,3..5) in basic, pe3 was not present */
  397. ex0,ex1,ex2,  /* ecl(epoch), 1/T, 1/T^2 */
  398. /* Pd(N,6..8) in basic */
  399. kn0,kn1,kn2,kn3,/* node(epoch),seconds/T,  seconds/T^2,seconds/T^3 */
  400. /* Pd(N,9..11) in basic, kn3 was not present */
  401. in0,in1,in2;    /* incl(epoch),1/T, 1/T^2 */
  402. /* Pd(N,12..14) in basic */
  403. };
  404.  
  405. struct kor {
  406.   int     j, i;
  407.   REAL8   lampl;  /* amplitude of disturbation in long, seconds of arc */
  408.   REAL8 lphase;   /* phase of disturbation in long, degrees */
  409.   INT4    rampl;  /* ampl. of disturbation in radius, 9th place of log */
  410.   REAL8   rphase; /* phase of disturbation in radius, degrees */
  411.   int     k;      /* index into disturbing planet anomaly table sa[] */
  412. };
  413.  
  414. struct sdat {   /* 0..19 mean anomalies of disturbing planets 
  415.   Sd(0..19,0..1) in basic */
  416.   REAL8 sd0,  /* mean anomaly at epoch 1850 */
  417.   sd1;  /* degrees/year */
  418. };
  419.  
  420. /* moon correction data; revised 30-jul-88: all long. to 0.3" */
  421. struct m45dat {   
  422.   int  i0,i1,i2,i3;
  423.   REAL8 lng,lat,par;
  424. };
  425.  
  426. extern struct eledata pd[MARS + 1];
  427. extern struct kor earthkor[];
  428. extern struct kor mercurykor[];
  429. extern struct kor venuskor[];
  430. extern struct kor marskor[];
  431. extern struct sdat _sd [SDNUM];
  432. extern struct m45dat m45[NUM_MOON_CORR];
  433. extern REAL8 rmima[CALC_N][2];  
  434. extern REAL8 ekld[4];
  435. extern REAL8 sa[SDNUM];
  436. extern double degnorm();
  437.  
  438. /*******************************************
  439. $Header: astrolib.h,v 1.2 91/11/16 16:21:02 alois Exp $
  440. astrolib.h
  441.  
  442. *******************************************/
  443.  
  444. /* macros for bit operations */
  445.  
  446. #define clear_bit(v,bit_nr) ((v) & ~(1L << (bit_nr)))
  447. #define set_bit(v,bit_nr)   ((v) | (1L << (bit_nr)))
  448. #define bit(bit_nr)         (1L << (bit_nr))
  449. #define check_bit(v,bit_nr) ((v) & (1L << (bit_nr)))
  450.  
  451. #endif /* PLACALC */
  452.  
  453. /* placalc.h */
  454.